import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_map/flutter_map.dart';
import 'package:latlong2/latlong.dart';
import 'gmapHelper.dart';
import 'layeroption.dart';
import 'gpsHelper.dart';

class LayerHelper {
  static List<LayerOptions> layerList(List<LayerOption> xList) {
    var a = <LayerOptions>[];
    for (var item in xList) {
      if (item.TypeId == 1) a.add((markerLayer(item)));
      if (item.TypeId == 2) a.add((polylineLayer(item)));
      if (item.TypeId == 3) a.add((polygonLayer(item)));
    }
    return a;
  }

  static LayerOptions markerLayer(LayerOption x) {
    var p1 = GpsHelper.StringToPointList(x.Points);
    if (p1.length == 0)
      return GMapHelper.MarkerLayer(new LatLng(42.0, 123.0), Icons.location_on,
          Color.fromARGB(0, x.ColorR, x.ColorG, x.ColorB));

    return GMapHelper.MarkerLayer2(
        p1[0],
        Icons.location_on,
        Color.fromARGB(x.ColorA, x.ColorR, x.ColorG, x.ColorB),
        x.LayerName,
        x.Remarks);
  }

  static LayerOptions polylineLayer(LayerOption x) {
    var p1 = GpsHelper.StringToPointList(x.Points);
    return GMapHelper.PolylineLayer(p1, x.LineWidth,
        Color.fromARGB(x.ColorA, x.ColorR, x.ColorG, x.ColorB));
  }

  static LayerOptions polygonLayer(LayerOption x) {
    var p1 = GpsHelper.StringToPointList(x.Points);
    return GMapHelper.PolygonLayer(p1, x.LineWidth,
        Color.fromARGB(x.ColorA, x.ColorR, x.ColorG, x.ColorB));
  }
}
